package com.ygq.controller;

import DTO.*;
import com.ygq.JudgeQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.PageResult;
import result.Result;

@RestController
@RequestMapping("/teacher/Judge")
public class JudgeQuestionController {

    @Autowired
    private JudgeQuestionService judgeQuestionService;

    /**
     * 分页查询
     * @param pageJudgeQuestionDTO
     * @return
     */
    @PostMapping("/getJudgeQuestion")
    public Result<PageResult> getJudgeQuestion(@RequestBody PageJudgeQuestionDTO pageJudgeQuestionDTO){
        PageResult pageResult = judgeQuestionService.page(pageJudgeQuestionDTO);
        return Result.success(pageResult);
    }

    /**
     * 添加题目
     * @param addJudgeDTO
     * @return
     */
    @PostMapping("/addQuestion")
    public Result<String> addQuestion(@RequestBody AddJudgeDTO addJudgeDTO){
        judgeQuestionService.addQuestion(addJudgeDTO);
        return Result.success("ok");
    }

    @PostMapping("/updateQuestion")
    public Result<String> updateQuestion(@RequestBody UpdateJudgeQuestionDTO updateJudgeQuestionDTO){
        if(judgeQuestionService.updateJudge(updateJudgeQuestionDTO)==1){
            return Result.error("该题目关联了试卷，不能修改",512);
        }
        return Result.success("ok");
    }

    /**
     * 删除题目
     * @param id
     * @return
     */
    @DeleteMapping("/deleteQuestion")
    public Result<String> deleteQuestion(Integer id){
        if(judgeQuestionService.deleteQuestion(id)==1){
            return Result.error("该题目关联了试卷，不能删除",512);
        };
        return Result.success("ok");
    }
}
